import { queryDetailReq, queryNodeDetailReq } from './api'

export default {
  namespace: 'operationDetail',
  state: {
    nodeInfoData: {},
  },
  effects: {
    * queryDetail({ params, cb }, { call, put }) {
      const res = yield call(queryDetailReq, params)
      if (cb) {
        cb(res)
      }
    },
    * queryNodeDetail({ params, cb }, { call, put }) {
      const res = yield call(queryNodeDetailReq, params) || {}
      yield put({
        type: 'save',
        payload: {
          nodeInfoData: res,
        },
      })
      if (cb) {
        cb(res)
      }
    },
    * clearNodeInfoData({ params, cb }, { call, put }) {
      yield put({
        type: 'save',
        payload: {
          nodeInfoData: {},
        },
      })
    },
  },
  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      }
    },
  },
}
